package Sort;

import java.util.Arrays;
import java.util.Random;

public class Test1 {
    Sorts sorts = new Sorts();

    public void orderSort(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    public void reverseSort(int[] array) {
        int j = 0;
        for (int i = array.length; i >= 0; i--) {
            if (j == array.length) {
                break;
            }
            array[j] = i;
            j++;
        }
    }

    public void initSort(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(array.length);
        }
    }

    public void testInitSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, 2 * array.length);
        reverseSort(tmpArray);
        long startTime = System.currentTimeMillis();
        sorts.ShellSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序：" + (endTime - startTime));
    }

    public void testInitSort1(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, 2 * array.length);
        reverseSort(tmpArray);
        long startTime = System.currentTimeMillis();
        sorts.SelectSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序：" + (endTime - startTime));
    }

    public void testInitSort2(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, 2 * array.length);
        reverseSort(tmpArray);
        long startTime = System.currentTimeMillis();
        sorts.InsertSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序：" + (endTime - startTime));
    }

    public void testInitSort3(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, 2 * array.length);
        reverseSort(tmpArray);
        long startTime = System.currentTimeMillis();
        sorts.bubblingSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序：" + (endTime - startTime));
    }
}
